package com.simp.app.ui.activity;

import java.util.List;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.antonioleiva.mvpexample.app.R;
import com.simp.app.base.BaseActivity;
import com.simp.app.presenter.MainPresenter;
import com.simp.app.presenter.impl.MainPresenterImpl;
import com.simp.app.view.MainView;

public class MainActivity extends BaseActivity implements MainView,AdapterView.OnItemClickListener {
	private ListView listView;
	private ProgressBar progressBar;
	private MainPresenter presenter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		listView = (ListView) findViewById(R.id.list);
		listView.setOnItemClickListener(this);
		progressBar = (ProgressBar) findViewById(R.id.progress);
		presenter = new MainPresenterImpl(this);
	}
	@Override
	protected void onResume() {
		super.onResume();
		presenter.onResume();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void showProgress() {
		progressBar.setVisibility(View.VISIBLE);
		listView.setVisibility(View.INVISIBLE);
	}

	@Override
	public void hideProgress() {
		progressBar.setVisibility(View.INVISIBLE);
		listView.setVisibility(View.VISIBLE);
	}

	@Override
	public void setItems(List<String> items) {
		listView.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items));
	}

	@Override
	public void showMessage(String message) {
		Toast.makeText(this, message, Toast.LENGTH_LONG).show();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		presenter.onItemClicked(position);
	}
}
